SlashCmdList['RELOADUI'] = ReloadUI
SLASH_RELOADUI1 = '/rl'

local f = CreateFrame('Frame',nil,UIParent)
local font = 'Interface\\Addons\\Test\\Font\\Ankle.ttf'
local size = 24
local color,r,g,b
local posx,posy = -200,-100

function f:Setup()
	local cur,max  = UnitHealth('player'),UnitHealthMax('player')
	pHP = f:CreateFontString(nil,'OVERLAY')
	pHP:SetFont(font,size,'OUTLINE')
	pHP:SetPoint('CENTER',UIParent,'CENTER',posx,posy)
	pHP:SetText(cur..'|cffff0000/|r'..max)
	pHP:SetTextColor(49/255, 207/255, 37/255)
	
	local cur,max  = UnitMana('player'),UnitManaMax('player')
	pMP = f:CreateFontString(nil,'OVERLAY')
	pMP:SetFont(font,size,'OUTLINE')
	pMP:SetPoint('TOP',pHP,'BOTTOM',0,-10)
	pMP:SetText(cur..'|cffff0000/|r'..max)
	pMP:SetTextColor(48/255, 113/255, 191/255)
	
	tHP = f:CreateFontString(nil,'OVERLAY')
	tHP:SetFont(font,size,'OUTLINE')
	tHP:SetPoint('LEFT',pHP,'RIGHT',300,0)
	
	tMP = f:CreateFontString(nil,'OVERLAY')
	tMP:SetFont(font,size,'OUTLINE')
	tMP:SetPoint('TOP',tHP,'BOTTOM',0,-10)
	tMP:SetTextColor(48/255, 113/255, 191/255)

	tLevel = f:CreateFontString(nil,'OVERLAY')
	tLevel:SetPoint('BOTTOMLEFT',tHP,'TOPLEFT',0,10)
	tLevel:SetFont(font,size,'OUTLINE')
	
	tName = f:CreateFontString(nil,'OVERLAY')
	tName:SetFont(font,size,'OUTLINE')
	tName:SetPoint('LEFT',tLevel,'RIGHT',10,0)
	
	tT = f:CreateFontString(nil,'OVERLAY')
	tT:SetFont(font,size,'OUTLINE')
	tT:SetPoint('TOP',tMP,'BOTTOM',0,-10)
	f:SetAlpha(0)
end

function f:UpdateHealth()
		local cur,max  = UnitHealth('player'),UnitHealthMax('player')
		pHP:SetText(cur..'|cffff0000/|r'..max) 
		local cur,max  = UnitHealth('target'),UnitHealthMax('target')
		tHP:SetText(UnitIsDead('target') and 'Dead' or (cur..'|cffff0000/|r'..max) ) 
end
function f:UpdatePower()
		local cur,max  = UnitMana('player'),UnitManaMax('player')
		pMP:SetText(cur..'|cffff0000/|r'..max) 
		local cur,max  = UnitMana('target'),UnitManaMax('target')
		tMP:SetText(max == 0 and '' or (cur..'|cffff0000/|r'..max))
end

function f:UpdateTarget()
		f:SetAlpha(UnitExists('target') and 0.5 or 0)
		if not UnitExists('target') or not UnitExists('targettarget') then 
														tLevel:SetText()
														tName:SetText()
														tHP:SetText()
														tMP:SetText()
														tT:SetText()
		end
		local cur,max  = UnitHealth('target'),UnitHealthMax('target')
		local level, name = UnitLevel('target'), UnitName('target')
		if UnitExists('target') then 
																tLevel:SetText(level)
																tName:SetText(name)
			local c,r,g,b
			c= UnitIsPlayer('target') and RAID_CLASS_COLORS[select(2, UnitClass('target'))] or UnitReactionColor[UnitReaction('playertarget', 'player')]
			r,g,b = c.r,c.g,c.b
			tName:SetTextColor(r,g,b,1)
			c= GetDifficultyColor(UnitLevel('target'));
			r,g,b = c.r,c.g,c.b
			tLevel:SetTextColor(r,g,b,1)
		end
		 tHP:SetText(UnitIsDead('target') and 'Dead' or (cur..'|cffff0000/|r'..max) ) 
		if UnitIsDead('target') or UnitIsTapped('target') then tHP:SetTextColor(0.6, 0.6, 0.6) else tHP:SetTextColor(49/255, 207/255, 37/255) end
		local cur,max  = UnitMana('playertarget'),UnitManaMax('target')
		tMP:SetText(max == 0 and '' or (cur..'|cffff0000/|r'..max))

end
function f:UpdateToT()
if UnitExists('targettarget') then
	if UnitIsUnit('targettarget', 'player') then tT:SetText('>> |cffff0000YOU|r <<') else 
					local  c,r,g,b
					c= UnitIsPlayer('targettarget') and RAID_CLASS_COLORS[select(2, UnitClass('targettarget'))] or UnitReactionColor[UnitReaction('targettarget', 'player')]
					r,g,b = c.r,c.g,c.b
					tT:SetTextColor(r,g,b,1)
					tT:SetText(UnitName('targettarget')) end
end
end

function f:onEvent(event)
	if event == 'PLAYER_LOGIN' then self:Setup() 
	elseif event == 'UNIT_HEALTH' then self:UpdateHealth()
	elseif event == 'UNIT_MANA' then self:UpdatePower()
	elseif event == 'PLAYER_TARGET_CHANGED' then self:UpdateTarget()
	elseif event == 'UNIT_TARGET'   then self:UpdateToT()
	elseif event == 'PLAYER_REGEN_ENABLED' then f:SetAlpha(0)
	elseif event == 'PLAYER_REGEN_DISABLED' then f:SetAlpha(1)
	end
end

function f:New()
	self:SetScript('OnEvent',self.onEvent)
	self:RegisterEvent('PLAYER_LOGIN')
	self:RegisterEvent('UNIT_HEALTH')
	self:RegisterEvent('UNIT_MANA')
	self:RegisterEvent('UNIT_TARGET')
	self:RegisterEvent('PLAYER_TARGET_CHANGED')
	self:RegisterEvent('PLAYER_REGEN_ENABLED')
	self:RegisterEvent('PLAYER_REGEN_DISABLED')
end

f:New()